
<form id='pub_msg' action='/events/pub/<%=@channel%>' method='GET'>
	<input type='hidden' name='user' value='<%=@current_user.name;%>' />
	<input type='text' name='msg' />
	<input type='submit' value='Send' />
</form>

<div>
<ul id='msg_list'>
	<li>-</li>
</ul>
</div>

<script type="text/javascript" language="javascript" charset="utf-8">
// <![CDATA[

$(function() {
	$("#pub_msg").submit(function(event) {
		event.preventDefault(); 
		var $form = $( this ),
		url = $form.attr( 'action' );

		term = $form.find( 'input[name="msg"]' ).val();
		text = $form.find( 'input[name="msg"]' ).val();
		user = $form.find( 'input[name="user"]').val();
		time = new Date();

		/* Send the data using post and put the results in a div */
		$.get( url, { msg: term}, function(data) {} );
	});

	var events_lp = function() {
		$.ajax({
			url: '/events/sub/<%=@channel%>',
			cache: false,
			success: function(data) {
				$('#msg_list li:gt(30)').remove();
				$('#msg_list:first-child').prepend('<li>' + data + '</li>');
				events_lp();
			},
			statusCode: { 
				404: function() {
					setTimeout(events_lp, 3000);
				},
				502: function() {
					events_lp();
				}
			}
		});
	};

	events_lp();
});
// ]]>
</script>
